package com.Controller;

import com.Common.Result;
import com.Service.EmployeeService;
import com.Service.impl.EmployeeServiceImpl;
import com.Util.RespUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description:
 * @author: hkw14
 * @time: 2021/5/6 9:57
 */
@WebServlet("/emp.do")
public class EmpServlet extends HttpServlet {
    private static final long serialVersionUID = -5330098911355362719L;
    EmployeeService employeeService = new EmployeeServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String type = req.getParameter("service");
        try {
            //利用反射调用方法
            this.getClass().getDeclaredMethod(type, HttpServletRequest.class,HttpServletResponse.class).invoke(this, req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void departList(HttpServletRequest request,HttpServletResponse response){
        Result list = employeeService.getPartmentList();
        RespUtil.write(response,list);
    }
}
